Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove needless initobj for default values and local arising from out args #5110

Merged
merged 6 commits into from
Sep 13, 2018

Conversation

dsyme
Copy link
Contributor

@dsyme dsyme commented Jun 6, 2018

This address #3057

  1. For various constructs like

    let result, elem = dict.TryGetValue(0)
    

    we emit an initobj instruction to zero-initialise a local. But locals are already zero-initialized in .NET IL.
    So we can just skip this instruction for "let x = DEFAULT in ..."

  2. outArg temporaries are only transiently mutable

This changes the assembly code for let result, elem = dict.TryGetValue(0) from:

00007FFAAD4B04E0  xor         r8d,r8d  
00007FFAAD4B04E3  mov         qword ptr [rsp+20h],r8  
00007FFAAD4B04E8  mov         r8,qword ptr [rsp+20h]  
00007FFAAD4B04ED  mov         qword ptr [rsp+28h],r8  
00007FFAAD4B04F2  lea         r8,[rsp+28h]  
00007FFAAD4B04F7  mov         rcx,rsi  
00007FFAAD4B04FA  xor         edx,edx  
00007FFAAD4B04FC  call        00007FFB0BA55E70  
00007FFAAD4B0501  movzx       ecx,al  
00007FFAAD4B0504  mov         rdx,qword ptr [rsp+28h]  
00007FFAAD4B0509  mov         qword ptr [rsp+20h],rdx  

to

00007FFAAD4A055B  lea         r8,[rsp+28h]  
00007FFAAD4A0560  mov         rcx,rsi  
00007FFAAD4A0563  xor         edx,edx  
00007FFAAD4A0565  call        00007FFB0BA55E70  
00007FFAAD4A056A  movzx       ecx,al  

@dsyme dsyme changed the title remove needless initobj for default values remove needless initobj and temporary for default values arising from out args Jun 6, 2018
@dsyme dsyme changed the title remove needless initobj and temporary for default values arising from out args remove needless initobj for default values and local arising from out args Jun 6, 2018
@dsyme dsyme changed the title remove needless initobj for default values and local arising from out args [CompilerPerf] remove needless initobj for default values and local arising from out args Jun 6, 2018
@dsyme
Copy link
Contributor Author

dsyme commented Jun 8, 2018

I checked compiler perf and results seem unaffected by this (but it's still a good change to take - just checking there were no adverse effects)

https://github.com/dsyme/visualfsharp.git minvars                      129c600eaac62a976377c3c668870dde39a7f1f3 b99f487554dec970c841e5fcea5d7ccd2f09216e MSRC-3617253 250.22 10.06                34.46                44.80                55.67                57.95               
https://github.com/Microsoft/visualfsharp master                       b99f487554dec970c841e5fcea5d7ccd2f09216e b99f487554dec970c841e5fcea5d7ccd2f09216e MSRC-3617253 249.94 9.93                34.61                45.32                56.05                57.91               
https://github.com/dsyme/visualfsharp.git bool2                        1212562a6551e6854f320d8600a9cf6146aee681 59d48cf44a26830793cd1c9c0a1b0d28bd34adef MSRC-3617253 250.26 9.87                34.23                44.49                54.95                58.06               
https://github.com/dsyme/visualfsharp.git opt5                         655dd7c2fccd09d96dd0bbc2f9146ef863a64b04 59d48cf44a26830793cd1c9c0a1b0d28bd34adef MSRC-3617253 249.45 9.89                33.94                45.48                56.10                57.95               
https://github.com/dsyme/visualfsharp.git minvars                      129c600eaac62a976377c3c668870dde39a7f1f3 59d48cf44a26830793cd1c9c0a1b0d28bd34adef MSRC-3617253 248.60 9.64                34.27                44.60                55.56                58.64               
https://github.com/Microsoft/visualfsharp master                       59d48cf44a26830793cd1c9c0a1b0d28bd34adef 59d48cf44a26830793cd1c9c0a1b0d28bd34adef MSRC-3617253 249.06 9.77                34.39                45.23                55.77                57.76               
https://github.com/dsyme/visualfsharp.git bool2                        1212562a6551e6854f320d8600a9cf6146aee681 59d48cf44a26830793cd1c9c0a1b0d28bd34adef MSRC-3617253 248.39 9.78                33.76                44.50                55.83                57.76               
https://github.com/dsyme/visualfsharp.git opt5                         655dd7c2fccd09d96dd0bbc2f9146ef863a64b04 59d48cf44a26830793cd1c9c0a1b0d28bd34adef MSRC-3617253 248.47 9.83                33.97                45.27                56.14                58.45               
https://github.com/dsyme/visualfsharp.git minvars                      129c600eaac62a976377c3c668870dde39a7f1f3 59d48cf44a26830793cd1c9c0a1b0d28bd34adef MSRC-3617253 249.10 9.65                34.39                44.76                55.29                58.09               
https://github.com/Microsoft/visualfsharp master                       59d48cf44a26830793cd1c9c0a1b0d28bd34adef 59d48cf44a26830793cd1c9c0a1b0d28bd34adef MSRC-3617253 247.74 9.95                34.16                44.87                56.31                58.37               
https://github.com/dsyme/visualfsharp.git bool2                        1212562a6551e6854f320d8600a9cf6146aee681 59d48cf44a26830793cd1c9c0a1b0d28bd34adef MSRC-3617253 249.24 9.67                33.82                44.51                55.94                58.77               
https://github.com/dsyme/visualfsharp.git opt5                         655dd7c2fccd09d96dd0bbc2f9146ef863a64b04 59d48cf44a26830793cd1c9c0a1b0d28bd34adef MSRC-3617253 248.10 9.62                34.14                45.47                56.45                58.21               
https://github.com/dsyme/visualfsharp.git minvars                      129c600eaac62a976377c3c668870dde39a7f1f3 59d48cf44a26830793cd1c9c0a1b0d28bd34adef MSRC-3617253 248.05 9.66                34.07                45.04                55.81                58.07               
https://github.com/Microsoft/visualfsharp master                       59d48cf44a26830793cd1c9c0a1b0d28bd34adef 59d48cf44a26830793cd1c9c0a1b0d28bd34adef MSRC-3617253 248.42 9.66                34.59                45.16                56.24                57.42               

@dsyme dsyme changed the title [CompilerPerf] remove needless initobj for default values and local arising from out args remove needless initobj for default values and local arising from out args Jun 8, 2018
@KevinRansom KevinRansom reopened this Sep 12, 2018
@KevinRansom KevinRansom merged commit 7dbfae8 into dotnet:master Sep 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants